#include "SemanticNodeConstructObject.h"

SemanticNodeConstructObject::SemanticNodeConstructObject(const SyntaxTreeNode *constructObjectNode, SemanticNode *parent) : SemanticNode(parent), ValueType(getNextUniqueID()) {
	if (constructObjectNode->Nodes->GetData(2)->Nodes->GetCount() > 0) {
	 for (int x = 0; x < constructObjectNode->Nodes->GetData(2)->Nodes->GetCount(); ++x) {
	 	expressions.push_back(constructObjectNode->Nodes->GetData(2)->Nodes->GetData(x)->Nodes->GetData(1));
	 }
	}

	SyntaxTreeNode *varType = constructObjectNode->Nodes->GetData(1);
	setType(varType, expressions.size());
}
/**
 *  @fn	std::vector<constSyntaxTreeNode*> SemanticNodeConstructObject::getArrayExpressions(void)
 * 
 *  @brief	.
 * 
 *  @author	Nikola Novak.
 *  @date	6/18/2009.
 * 
 *  @return	.
 */
std::vector<const SyntaxTreeNode*> SemanticNodeConstructObject::getArrayExpressions(void) {
	return expressions;
}
/**
 *  @fn	void SemanticNodeConstructObject::addArguments(std::vector<SemanticNodeExpression*> argList
 *  	)
 * 
 *  @brief	.
 * 
 *  @author	Nikola Novak.
 *  @date	6/18/2009.
 * 
 *  @param	argList	.
 */
void SemanticNodeConstructObject::addArguments(std::vector<SemanticNodeExpression*> argList) {
	for (std::vector<SemanticNodeExpression *>::iterator i = argList.begin(); i != argList.end(); ++i) addArgument(*i);
}
/**
 *  @fn	void SemanticNodeConstructObject::addArgument(SemanticNodeExpression *argument)
 * 
 *  @brief	.
 * 
 *  @author	Nikola Novak.
 *  @date	6/18/2009.
 * 
 *  @param	argument	.
 */
void SemanticNodeConstructObject::addArgument(SemanticNodeExpression *argument) {
	arguments.push_back(argument);
}
/**
 *  @fn	void SemanticNodeConstructObject::addDimension(SemanticNodeExpression *dimension)
 * 
 *  @brief	.
 * 
 *  @author	Nikola Novak.
 *  @date	6/18/2009.
 * 
 *  @param	dimension	.
 */
void SemanticNodeConstructObject::addDimension(SemanticNodeExpression *dimension) {
	dimensions.push_back(dimension);
}
/**
 *  @fn	std::string SemanticNodeConstructObject::toDebugString(int tab)
 * 
 *  @brief	.
 * 
 *  @author	Nikola Novak.
 *  @date	6/17/2009.
 * 
 *  @param	tab	.
 * 
 *  @return	.
 */
std::string SemanticNodeConstructObject::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	res << "new " << getTypeDebugString();
	if (dimensions.size() > 0) {
		res << " [" << std::endl;
	 for (std::vector<SemanticNodeExpression *>::iterator e = dimensions.begin(); e != dimensions.end(); ) {
	 	res << ((SemanticNode *)(*e))->toDebugString(tab + 1);
	 	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	 	if (++e != dimensions.end()) res << "][" << std::endl;
	 }
		res << "]" << std::endl;
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	}
	res << "(";
	if (arguments.size() > 0) {
		res << std::endl;
	 for (std::vector<SemanticNodeExpression *>::iterator i = arguments.begin(); i != arguments.end(); ++i)
	 	res << ((SemanticNode *)(*i))->toDebugString(tab + 1);
	 for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	}
	res << ")" << std::endl;
	return res.str();
}
